/**
* @Author: 路博欢
* @Date: 2019/12/18
* @Version: 1.0
* @Last Modified by: 路博欢
* @Last Modified time: 2019/12/18
**/
<comment>
  # 任务模式 生成整改单
</comment>
<template>
  <div id="CreateBill" class="p-box">
    <div class="p-return">
      <mu-appbar color="primary" class="lan-header">
        <mu-button icon slot="left" v-close>
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>生成整改单
      </mu-appbar>
    </div>
    <div class="p-content" style="background: #fff;" v-show="!measurePointsForms.length&&!loading">
      <NoData />
    </div>
    <div
      class="p-content"
      ref="$content"
      v-show="measurePointsForms.length"
      style="background: #fff;padding: 0.14rem;"
    >
      <!-- <div
      style="height:calc(100vh - .45rem);overflow: auto;background: #fff;padding: 0 14px;"

      v-if="measurePointsForms.length && loading || true"
      >-->
      <mu-card class="card-point" v-for="(point, index) in measurePointsForms" :key="index">
        <mu-expansion-panel
          :class="point.prop == 100 ? 'qualified' : 'unqualified'"
          :expand="active == point.id"
          @change="toggle(point)"
        >
          <div slot="header" style="width: 100%;">
            <div style="width: 100%; ">
              <div
                class="ly_flex ly_flex_just_between"
                style="padding: 0 14px;height: 0.39rem;line-height: 0.39rem;font-size:0.14rem"
              >
                <div>实测{{point.pointNum}}</div>
                <div @click.stop="del(index)" v-if="point.canDel=='0'">
                  <i class="iconfont iconSshanchu" style="color:#0080CB"></i>
                </div>
                <div @click.stop="del(index)" v-if="point.canDel=='1'">已生成整改通知单</div>
              </div>
              <mu-divider></mu-divider>
              <div class="sub-container">
                <div class="sub-box">
                  <span class="sub-title">实测分项：</span>
                  <span class="sub-content">{{point.subentryName}}</span>
                </div>
                <div class="sub-box">
                  <span class="sub-title">实测内容：</span>
                  <span class="sub-content">{{point.content}}</span>
                </div>
                <div class="sub-box">
                  <span class="sub-title">实测结果：</span>
                  <span class="sub-content">
                    <span class="mBadge">{{point.result=='1' ? '合格' : '不合格'}}</span>
                  </span>
                </div>
              </div>
            </div>
          </div>
          <mu-container ref="container" class="lan-loadmore-content no-padding">
            <mu-form :model="point" class="mu-lan-form" :label-position="'left'" label-width>
              <mu-form-item label="项目名称" class="form-between required">
                <span class="normal-font-size form-right-text">{{point.projectName}}</span>
                <!--  @click="open('org')" -->
                <!-- <i class="iconfont angle-left iconangle-right"></i> -->
              </mu-form-item>
              <mu-form-item label="所属区域" class="form-between required">
                <span class="normal-font-size form-right-text">{{point.areaName}}</span>
                <!-- <span
                  class="normal-font-size form-right-text"
                  @click="open('area')"
                >{{point.areaName ? point.areaName : '请选择'}}</span>
                <i class="iconfont angle-left iconangle-right"></i>-->
              </mu-form-item>
              <mu-form-item label="责任单位" class="form-between required">
                <span class="normal-font-size form-right-text">{{point.deptName}}</span>
              </mu-form-item>
              <mu-form-item label="问题类型" class="form-between required">
                <!-- <mu-select
                  v-model="point.problemType"
                  @change="(val)=>problemTypeChange(val,index)"
                  placeholder="请选择"
                  :readonly="point.canDel=='0'?false:true"
                  popover-class="lan-popover-select"
                >
                  <mu-option label="其他" value="0"></mu-option>
                  <mu-option
                    v-for="(list,index) in problemTypes"
                    :key="index"
                    :label="list.problemTypeId"
                    :value="list.id"
                  ></mu-option>
                </mu-select> -->
                <!-- <i class="iconfont angle-left iconangle-right"></i> -->
                <span class="normal-font-size form-right-text" v-if="point.canDel=='0'" @click="openNowPro(index)">{{point.problemType?point.problemTypeName:'请选择'}}</span>
                <span class="normal-font-size form-right-text" v-else >{{point.problemType?point.problemTypeName:'请选择'}}</span>
                <i v-if="point.problemType && point.problemType != -1" class="iconfont iconwenhao" @click="openTips(index)"></i>
                <i v-if="!point.problemType || point.problemType == -1" class="iconfont angle-left iconangle-right"></i>
              </mu-form-item>
              <mu-form-item
                label="问题备注"
                class="form-between required inline-item"
                v-if="point.problemType=='-1'"
              >
                <mu-text-field
                  :readonly="point.canDel=='0'?false:true"
                  v-model="point.problemElseRemark"
                  multi-line
                  placeholder="请输入"
                  :rows="4"
                  :rows-max="8"
                ></mu-text-field>
              </mu-form-item>
              <mu-form-item label="问题等级" class="form-between required">
                <mu-radio
                  style="margin-right: 10px"
                  :key="level.value"
                  :readonly="point.canDel=='0'?false:true"
                  v-for="level in problemLevels"
                  :value="level.value"
                  v-model="point.problemLevel"
                  :label="level.label"
                ></mu-radio>
              </mu-form-item>
              <mu-form-item label="现场照片" class="inline-item required">
                <div class="ly_flex ly_flex_wrap_wrap">
                  <div
                    style="position: relative;width: .7rem;height: .7rem;margin-right: .095rem;margin-bottom: .08rem;border-radius:0.02rem;background:rgba(216,216,216,1);overflow: hidden"
                    v-for="(url, urlIndex) in handurl(point.scenePhotos)"
                    :key="urlIndex"
                  >
                    <img
                      :src="url"
                      style="transform: scale(1.5)"
                      @click="open('imgPreview',{list:point.scenePhotos,index:urlIndex})"
                      alt
                    />
                    <i
                      v-if=" point.canDel=='0'"
                      class="iconfont iconqingchu"
                      @click.stop="delImg(point, url)"
                      style="color: #FF4242;position: absolute;right: .05rem; top: 0;"
                    ></i>
                  </div>
                  <div style="margin: 0 .1rem .14rem 0;" v-if=" point.canDel=='0'">
                    <FileUpload @successed="confirm('imgUpload',{res: $event, point})" v-if="handurl(point.scenePhotos).length < 5" ></FileUpload>
                  </div>
                </div>

                <!-- <mt-switch v-model="form.useTable"></mt-switch> -->
              </mu-form-item>
              <mu-form-item label="问题描述" class="inline-item required">
                <mu-text-field
                  :readonly="point.canDel=='0'?false:true"
                  v-model="point.conVal"
                  multi-line
                  placeholder="请输入"
                  :rows="4"
                  :rows-max="8"
                ></mu-text-field>
              </mu-form-item>
              <mu-form-item label="平面图标记" class="inline-item">
                <MapShow
                  v-if="active == point.id"
                  :single="true"
                  :width="'100%'"
                  :url="point.photoUrl"
                  readonly
                  :points="[{lng:point.point.split(',')[0],lat:point.point.split(',')[1],left:point.point.split(',')[0],top:point.point.split(',')[1]}]"
                ></MapShow>
              </mu-form-item>
              <!-- <mu-form-item label="整改期限" class="required">
                <mu-date-input
                  :readonly="point.canDel=='0'?false:true"
                  v-model="point.rectifyDto.endTime"
                  format="YYYY-MM-DD"
                  placeholder="请选择"
                  container="bottomSheet"
                  label-float
                ></mu-date-input>
                <i class="iconfont angle-left iconangle-right"></i>
              </mu-form-item>-->

              <mu-form-item label="整改期限" class="required">
                <mu-select
                  v-model="point.rectifyDto.days"
                  placeholder="请选择"
                  :readonly="point.canDel=='0'?false:true"
                  popover-class="lan-popover-select"
                >
                  <mu-option
                    v-for="(list,index) in daysList"
                    :key="index"
                    :label="list.name"
                    :value="list.id"
                  ></mu-option>
                </mu-select>
                <i class="iconfont angle-left iconangle-right"></i>
              </mu-form-item>
              <mu-form-item label="整改要求" class="inline-item">
                <mu-text-field
                  :readonly="point.canDel=='0'?false:true"
                  v-model="point.rectifyDto.rectificationRequirements"
                  multi-line
                  placeholder="请输入"
                  :rows="4"
                  :rows-max="8"
                ></mu-text-field>
              </mu-form-item>
              <mu-form-item label="整改责任人" class="inline-item required hasPadding">
                <div
                  class="userBox"
                  style
                  v-for="(user, index) in point.rectifyDto.responsibleUsers"
                  :key="'u'+index"
                >
                  <div
                    class="ly_flex ly_flex_just_center ly_flex_ali_center add"
                  >{{user.label.substr(0,1)}}</div>
                  <span>{{user.label}}</span>
                  <i
                    v-if="point.canDel=='0'"
                    class="iconfont iconqingchu"
                    @click.stop="delUser('responsibleUser',point, user.value)"
                    style="color: #FF4242;position: absolute;right: .05rem; top: 0;"
                  ></i>
                </div>
                <div
                  style
                  @click="open('user', {point, type: 'responsibleUser'})"
                  v-if="point.canDel=='0'"
                >
                  <div class="userTrigger" @click="sheetVisible = true">
                    <div class="ly_flex ly_flex_just_center ly_flex_ali_center add">
                      <i class="iconfont iconplus"></i>
                    </div>
                    <span>添加人员</span>
                  </div>
                </div>
              </mu-form-item>

              <mu-form-item label="复查人" class="inline-item required hasPadding">
                <div
                  class="userBox"
                  v-for="(user, index) in point.rectifyDto.reviewUsers"
                  :key="'r'+index"
                >
                  <div
                    class="ly_flex ly_flex_just_center ly_flex_ali_center add"
                  >{{user.label.substr(0,1)}}</div>
                  <span>{{user.label}}</span>
                  <i
                    v-if="point.canDel=='0'"
                    class="iconfont iconqingchu"
                    @click.stop="delUser('reviewUser',point, user.value)"
                    style="color: #FF4242;position: absolute;right: .05rem; top: 0;"
                  ></i>
                </div>
                <div
                  style
                  @click="open('user', {point, type: 'reviewUser'})"
                  v-if="point.canDel=='0'"
                >
                  <div class="userTrigger" @click="sheetVisible = true">
                    <div class="ly_flex ly_flex_just_center ly_flex_ali_center add">
                      <i class="iconfont iconplus"></i>
                    </div>
                    <span>添加人员</span>
                  </div>
                </div>
              </mu-form-item>
              <mu-form-item label="抄送人" class="inline-item hasPadding" style="box-shadow:none">
                <div
                  class="userBox"
                  style
                  v-for="(user, index) in point.rectifyDto.rectCopyUsers"
                  :key="'c'+index"
                >
                  <div
                    class="ly_flex ly_flex_just_center ly_flex_ali_center add"
                  >{{user.label.substr(0,1)}}</div>
                  <span>{{user.label}}</span>
                  <i
                    v-if="point.canDel=='0'"
                    class="iconfont iconqingchu"
                    @click.stop="delUser('rectCopyUser',point, user.value)"
                    style="color: #FF4242;position: absolute;right: .05rem; top: 0;"
                  ></i>
                </div>
                <div
                  style
                  @click="open('user', {point, type: 'rectCopyUser'})"
                  v-if="point.canDel=='0'"
                >
                  <div class="userTrigger" @click="sheetVisible = true">
                    <div class="ly_flex ly_flex_just_center ly_flex_ali_center add">
                      <i class="iconfont iconplus"></i>
                    </div>
                    <span>添加人员</span>
                  </div>
                </div>
              </mu-form-item>
            </mu-form>
          </mu-container>
        </mu-expansion-panel>
      </mu-card>

      <mu-button full-width color="primary" style="margin:.2rem 0" @click="save">提交</mu-button>
    </div>
    <!-- 选项目 -->
    <Org
      ref="org"
      v-if="org.open"
      :open="org.open"
      :customRoot="org.customRoot"
      :orgType="org.orgType"
      @close="close('org')"
      v-model="org.res"
      @confirm="confirm('org')"
    ></Org>
    <!-- 选人 -->
    <User
      ref="User"
      v-if="user.open"
      :open="user.open"
      :multiple="user.multiple"
      :orgType="user.userType"
      @close="close('user')"
      v-model="user.res"
      @confirm="confirm('user')"
    ></User>
    <!--选择区域-->
    <!-- <SelectArea
      :open="area.open"
      v-model="area.res"
      :currentProject="area.currentProject"
      @close="close('area')"
      @confirm="confirm('area')"
    ></SelectArea>-->
    <!--图片预览-->
    <ImgPreview
      :imgUrls="imgPreviewObj.list"
      :open="imgPreviewObj.show"
      @close="closeImageDialog"
      :slideIndex="imgPreviewObj.index"
    ></ImgPreview>
    <FilePreview :fileUrl="imgPreview.imgUrl" :open="imgPreview.open" @close="close('imgPreview')"></FilePreview>

    <!-- 选择问题类型 -->
    <Qes ref="Qes" v-if="typeCon"  :open="typeCon"  @close="typeCon=false" @confirm="typeCon=false" @change="typeChange"></Qes>
  </div>
</template>

<script>
import ImgPreview from "@/preview/ImgPreview.vue";
import SelectArea from "@/select/area/Area.vue";
import Org from "@/select/org/Org.vue";
import User from "@/select/user/User.vue";
import FilePreview from "@/preview/FilePreview.vue";
import FileUpload from "@/fileUpload/FileUpload.vue";
import { MessageBox } from "mint-ui";
import Qes from "@/quseType/Qes.vue"
export default {
  name: "CreateBill",
  components: {
    SelectArea,
    Org,
    User,
    FilePreview,
    ImgPreview,
    FileUpload, 
    Qes
  },
  props: {},
  data() {
    return {
      imgPreviewObj: {
        list: [],
        index: 0,
        show: false
      },
      api: {
        getOrderDataApi: "/safety/measure/createdCorrectRece", // 获取整改单数据
        getProblemTypesApi: "/safety/problemItem/pageList", // 获取问题类型
        CreateBillApi: "/safety/measure/createdCorrectData" // 生成整改单
      },
      form: {
        projectId: "",
        areaId: "", //区域平面图id
        areaName: "",
        deptId: "", // 责任单位
        subentryId: "", //测量分项id
        subentryName: "", //分项名称
        taskId: "", //任务id
        value: "", //值
        conVal: "", // 测量结果
        content: "", // 测量内容
        point: "", // 点位坐标
        problemLevel: "1", // 问题等级
        problemType: "", // 问题类型
        responsibleUserId: "", // 整改责任人
        reviewUser: "", // 复查人
        responsibleUnitId: "", // 整改单位
        result: "", // 测量结果
        scenePhotos: "", // 现场照片
        rectifyDto: {
          days: 1, //是否立即整改
          endTime: "", //截止时间
          isCurrentRect: 0, //是否现场整改
          rectCopyUserIds: [] //抄送人
        }
      },
      daysList: [],
      // 组织选择
      org: {
        open: false,
        orgType: "currOrgProject",
        res: []
      },
      // 人员选择
      user: {
        open: false,
        userType: "currOrgProject",
        res: [],
        type: "",
        multiple: true
      },
      // 图片预览
      imgPreview: {
        open: false,
        imgUrl: ""
      },
      // 区域选择
      area: {
        open: false,
        currentProject: {},
        res: {}
      },
      // 图片上传
      imgUpload: {
        open: false
      },
      // 整改问题类型
      problemTypes: [],
      // 整改问题等级
      problemLevels: [
        {
          label: "重大",
          value: "3"
        },
        {
          label: "较大",
          value: "2"
        },
        {
          label: "一般",
          value: "1"
        }
      ],
      measureId: "",
      measurePoints: [
        {
          id: "166231910639475094",
          taskId: "164445163442143638",
          measureId: "166231910639468950", //测量id
          point: "10,20", //点位
          subentryId: "163058901544075670", //分项id
          subentryName: "钢筋", //分项名称
          content: "钢筋硬度", //实测内容
          value: "0", //测量值
          result: "0", //结果
          areaId: "159620695398023574", //区域id
          areaName: "一工区", //区域名称
          photoUrl:
            "http://autobuild.jiguantong.com:8087/safety/system/download?fileUrl=2019-10-17/QQ浏览器截图20190416140613.png",
          projectId: "60820458500522390", //项目id
          projectName: "隧道项目", //项目名称
          deptId: "60821144621547926", //单位id
          deptName: "测试1", //单位名称
          conVal: "钢筋  钢筋硬度  不合格" //拼接结果
        },
        {
          id: "1662319106394740702",
          taskId: "164445163442143638",
          measureId: "166231910639468950",
          point: "10,20",
          subentryId: "163058901544075670",
          subentryName: "钢筋",
          content: "钢筋截面积",
          value: "21",
          result: "0",
          areaId: "159620695398023574",
          areaName: "一工区",
          photoUrl:
            "http://autobuild.jiguantong.com:8087/safety/system/download?fileUrl=2019-10-17/QQ浏览器截图20190416140613.png",
          projectId: "60820458500522390",
          projectName: "隧道项目",
          deptId: "60821144621547926",
          deptName: "测试1",
          conVal: "钢筋  钢筋截面积  不合格"
        }
      ], // 整改单数据
      measurePointsForms: [], // 生成整改单数据
      active: "",
      loading: false,
      pointTemp: {},
      typeCon:false,
      nowIndex:''
    };
  },
  computed: {},
  created() {
    this.measureId = this.$route.query.measureId;
    for (let i = 1; i <= 30; i++) {
      this.daysList.push({
        name: i + "天",
        id: i
      });
    }
    this.getOrderData();
    this.getProblemTypes();
  },
  mounted() {},
  watch: {},
  methods: {
    openTips(index){
        MessageBox({
          title: '问题规范标准',
          message: this.measurePointsForms[index]['problemTypestandard'],
          confirmButtonText: '知道了'
        })
    },
    openNowPro(index){
      this.nowIndex = index
      this.typeCon = true;
    },
    typeChange(value){
      // this.typeName = value.problemTypeId
      // this.data.problemTypeId = value.id;
      // this.tyinfor = value
      // this.measurePointsForms[index]['problemTypeId'] = value.id;
      this.$set(this.measurePointsForms[this.nowIndex], "problemType", value.id);
      // this.measurePointsForms[index]['problemTypeName'] = value.problemTypeId;
      this.$set(this.measurePointsForms[this.nowIndex], "problemTypeName", value.problemTypeId);
      // this.measurePointsForms[index]['problemTypestandard'] = value.standard;
      this.$set(this.measurePointsForms[this.nowIndex], "problemTypestandard", value.standard);
      // this.nowIndex = ''
      this.problemTypeChange(value.id,this.nowIndex)
    },
    closeImageDialog() {
      this.imgPreviewObj.show = false;
    },

    // 获取问题类型
    getProblemTypes() {
      let obj = {
        list: [{}],
        obj: {},
        pageNo: -1,
        pageSize: 10
      };
      this.$A
        .Go("post", this.api.getProblemTypesApi, obj)
        .then(response => {
          this.$closeLoading();
          Util.processRes(response, () => {
            this.problemTypes = response.body.rows;
          });
          Util.processError(this, response);
        })
        .catch(err => {
          this.$closeLoading();
          console.log(err);
        });
    },
    //问题类型change事件
    problemTypeChange(val, index) {
      if (val == -1) {
        this.$set(this.measurePointsForms[index], "problemLevel", "1"); //问题等级
        this.$set(this.measurePointsForms[index].rectifyDto, "days", ""); // 整改期限
      } else {
        this.$A
          .Go("get", "/safety/problemItem/detail", { id: val })
          .then(res => {
            if (res.code == 200) {
              this.$set(
                this.measurePointsForms[index],
                "problemLevel",
                res.body.problemLevel
              ); //问题等级
              this.$set(
                this.measurePointsForms[index].rectifyDto,
                "days",
                res.body.rectificationPeriod
              ); // 整改期限
            } else {
            }
          });
      }
    },
    // 切换手风琴查看数据
    toggle(msp) {
       this.active = msp.id// === this.active ? '' : msp.id;
    },
    // 组件打开
    open(type, props = {}) {
      switch (type) {
        // 组织
        case "org":
          this.pointTemp = props.point;
          this.org.open = true;
          break;
        // 人员
        case "user":
          this.user.res = [];
          this.pointTemp = props.point;
          this.user.type = props.type;
          if (this.user.type == "reviewUser") {
            this.user.multiple = false;
            this.user.res = props.point.rectifyDto.reviewUsers || [];
          } else if (this.user.type == "responsibleUser") {
            this.user.multiple = false;
            this.user.res = props.point.rectifyDto.responsibleUsers || [];
          } else if (this.user.type == "rectCopyUser") {
            this.user.res = props.point.rectifyDto.rectCopyUsers || [];
            this.user.multiple = true;
          }
          this.user.open = true;
          break;
        // 区域
        case "area":
          this.area.open = true;
          break;
        // 图片预览
        case "imgPreview":
          let list = this.handurl(props.list);
          this.imgPreviewObj = {
            list: list,
            show: true,
            index: props.index
          };
          break;
        // 图片上传
        case "imgUpload":
          this.imgUpload.oen = true;
          break;
      }
    },
    // 组件弹窗关闭
    close(type, props = {}) {
      switch (type) {
        // 组织
        case "org":
          this.org.open = false;
          break;
        // 人员
        case "user":
          this.user.open = false;
          break;
        // 区域
        case "area":
          this.area.open = false;
          break;
        // 图片预览
        case "imgPreview":
          this.imgPreview.open = false;
          break;
        // 图片上传
        case "imgUpload":
          this.imgUpload.oen = false;
          break;
      }
    },
    // 结果确认
    confirm(type, props) {
      switch (type) {
        // 组织
        case "org":
          this.pointTemp.deptId = this.org.res[0].value;
          this.pointTemp.deptName = this.org.res[0].label;
          this.org.open = false;
          break;
        // 人员
        case "user":
          this.user.open = false;
          this.addUser(this.user.type);
          break;
        // 区域
        case "area":
          this.area.open = false;
          break;
        // 图片预览
        case "imgPreview":
          this.imgPreview.open = false;
          break;
        // 图片上传
        case "imgUpload":
          this.addImg(
            props.point,
            this.$A.baseUrl[0] +
              "/safety/system/download?fileUrl=" +
              props.res.body
          );
          this.imgUpload.oen = false;
          break;
      }
    },

    handurl(str) {
      if (!str) {
        return [];
      } else {
        return str.split(",");
      }
    },
    // 添加人员
    addUser(type) {
      let ids = [];
      this.user.res.forEach(u => {
        if (!ids.includes(u.value)) {
          ids.push(u.value);
        }
      });
      switch (type) {
        case "rectCopyUser":
          this.pointTemp.rectifyDto.rectCopyUsers = this.user.res;
          this.pointTemp.rectifyDto.rectCopyUserIds = ids;
          break;
        case "reviewUser":
          this.pointTemp.rectifyDto.reviewUsers = this.user.res;
          this.pointTemp.rectifyDto.reviewUser = ids;
          break;
        case "responsibleUser":
          this.pointTemp.rectifyDto.responsibleUsers = this.user.res;
          this.pointTemp.rectifyDto.responsibleUserId = ids;
          break;
      }
    },
    // 删除人员
    delUser(type, point, id) {
      let ids = [];
      switch (type) {
        // 抄送人
        case "rectCopyUser":
          point.rectifyDto.rectCopyUsers.splice(
            point.rectifyDto.rectCopyUsers.findIndex(i => i.value == id),
            1
          );
          this.$forceUpdate();
          point.rectifyDto.rectCopyUsers.forEach(u => {
            if (!ids.includes(u.value)) {
              ids.push(u.value);
            }
          });
          point.rectifyDto.rectCopyUserIds = ids;
          break;
        // 复查人
        case "reviewUser":
          point.rectifyDto.reviewUsers.splice(
            point.rectifyDto.reviewUsers.findIndex(i => i.value == id),
            1
          );
          this.$forceUpdate();
          point.rectifyDto.reviewUsers.forEach(u => {
            if (!ids.includes(u.value)) {
              ids.push(u.value);
            }
          });
          point.rectifyDto.reviewUser = ids;
          break;
        // 责任人
        case "responsibleUser":
          point.rectifyDto.responsibleUsers.splice(
            point.rectifyDto.responsibleUsers.findIndex(i => i.value == id),
            1
          );
          this.$forceUpdate();
          point.rectifyDto.responsibleUsers.forEach(u => {
            if (!ids.includes(u.value)) {
              ids.push(u.value);
            }
          });
          point.rectifyDto.responsibleUserId = ids;
          break;
      }
    },
    // 添加照片
    addImg(point, url) {
      let arr = this.handurl(point.scenePhotos);
      arr.push(url);
      point.scenePhotos = arr.join(",");
    },
    // 删除照片
    delImg(point, url) {
      let arr = this.handurl(point.scenePhotos);
      arr.splice(arr.indexOf(url), 1);
      point.scenePhotos = arr.join(",");
    },
    // 验证表单
    validateForm() {
      try {
        this.measurePointsForms.length &&
          this.measurePointsForms.forEach((form, index) => {
            if (!form.projectId && form.canDel == "0") {
              //this.$A.MS(`点位${index + 1}中未选择项目`);
              this.$A.MS(`第${index + 1}条问题未选择项目`);
              throw new Error();
            }
            if (!form.areaId) {
              //this.$A.MS(`点位${index + 1}中未选择去区域`);
              this.$A.MS(`第${index + 1}条问题未选择去区域`);
              throw new Error();
            }

            if (!form.deptId) {
              //this.$A.MS(`点位${index + 1}中未选择责任单位`);
              this.$A.MS(`第${index + 1}条问题未选择责任单位`);
              throw new Error();
            }
            if (!form.problemType) {
              //this.$A.MS(`点位${index + 1}中未选择问题类型`);
              this.$A.MS(`第${index + 1}条问题未选择问题类型`);
              throw new Error();
            }
            if (form.problemType == "0" && !form.problemElseRemark) {
              //this.$A.MS(`点位${index + 1}中未选择去区域`);
              this.$A.MS(`第${index + 1}条问题类型为其他但是未填写问题备注`);
              throw new Error();
            }
            if (!form.problemLevel) {
              //this.$A.MS(`点位${index + 1}中未选择问题等级`);
              this.$A.MS(`第${index + 1}条问题未选择问题等级`);
              throw new Error();
            }

            if (!form.scenePhotos) {
              //this.$A.MS(`点位${index + 1}中未添加现场照片`);
              this.$A.MS(`第${index + 1}条问题未添加现场照片`);
              throw new Error();
            }

            if (!form.conVal) {
              //this.$A.MS(`点位${index + 1}中未填写任务描述`);
              this.$A.MS(`第${index + 1}条问题未填写问题描述`);
              throw new Error();
            }
            if (!form.rectifyDto.days) {
              //this.$A.MS(`点位${index + 1}中未选择截止时间`);
              this.$A.MS(`第${index + 1}条问题未选择整改期限`);
              throw new Error();
            }
            if (!form.rectifyDto.responsibleUserId) {
              //this.$A.MS(`点位${index + 1}中未选择整改责任人`);
              this.$A.MS(`第${index + 1}条问题未选择整改责任人`);
              throw new Error();
            }
            if (!form.rectifyDto.reviewUser) {
              //this.$A.MS(`点位${index + 1}中未选择复查人`);
              this.$A.MS(`第${index + 1}条问题未选择复查人`);
              throw new Error();
            }
          });
      } catch (e) {
        //console.log(e);
        return false;
      }
      return true;
    },
    // 获取点位测量历史
    getOrderData() {
      this.loading = true;
      this.$openLoading();
      this.$A
        .Go("get", this.api.getOrderDataApi, { measureId: this.measureId })
        .then(response => {
          this.loading = false;
          this.$closeLoading();
          Util.processRes(response, () => {
            if (response.body) {
              //按照点位的大小进行排序  升序
              response.body.sort((a, b) => {
                return a.pointNum.substring(2) - b.pointNum.substring(2);
              });
              //处理后台返回的数据
              response.body.forEach(point => {
                if (point.copyList && point.copyList.length) {
                  point.copyList.forEach(item => {
                    item.label = item.userName;
                    item.value = item.userId;
                  });
                } else {
                  point.copyList = [];
                }

                let form = {
                  id: point.id,
                  pointNum: point.pointNum,
                  canDel: point.canDel,
                  projectId: point.projectId,
                  projectName: point.projectName,
                  areaId: point.areaId, //区域平面图id
                  areaName: point.areaName,
                  deptId: point.deptId, // 责任单位
                  deptName: point.deptName,
                  subentryId: point.subentryId, //测量分项id
                  subentryName: point.subentryName, //分项名称
                  taskId: point.taskId, //任务id
                  content: point.content, // 测量内容
                  value: point.value, //值
                  conVal: point.conVal, // 测量结果（拼接）
                  point: point.point, // 点位坐标
                  photoUrl: point.photoUrl,

                  problemLevel: point.problemLevel ? point.problemLevel : "1", // 问题等级
                  problemType: point.problemType ? point.problemType : "", // 问题类型
                  problemTypeName: point.problemTypeName ? point.problemTypeName : "",
                  problemTypestandard: point.standard ? point.standard : "",
                  problemElseRemark: point.problemElseRemark
                    ? point.problemElseRemark
                    : "", //问题备注
                  result: point.result, // 测量结果
                  scenePhotos: point.scenePhotos ? point.scenePhotos : "" // 现场照片
                };
                /**
                 *  endTime:
                    point.rectifyVo && point.rectifyVo.endTime
                      ? new Date(point.rectifyVo.endTime)
                      : null,
                         isCurrentRect:
                    point.rectifyVo && point.rectifyVo.isCurrentRect
                      ? point.rectifyVo.isCurrentRect
                      : "", //是否现场整改
                 */
                form.rectifyDto = {
                  days:
                    point.rectifyVo && point.rectifyVo.days
                      ? point.rectifyVo.days
                      : null, //整改期限
                  rectificationRequirements:
                    point.rectifyVo && point.rectifyVo.rectificationRequirements
                      ? point.rectifyVo.rectificationRequirements
                      : "", //整改要求
                  responsibleUnitId:
                    point.rectifyVo && point.rectifyVo.responsibleUnitId
                      ? point.rectifyVo.responsibleUnitId
                      : "", //整改单位
                  rectCopyUserIds:
                    point.rectifyVo && point.rectifyVo.rectCopyUserIds
                      ? point.rectifyVo.rectCopyUserIds
                      : [],
                  responsibleUserId:
                    point.rectifyVo && point.rectifyVo.responsibleUserId
                      ? [point.rectifyVo.responsibleUserId]
                      : "", //整改责任人
                  reviewUser:
                    point.rectifyVo && point.rectifyVo.reviewUserId
                      ? [point.rectifyVo.reviewUserId]
                      : "", //复查人呢
                  rectCopyUsers: point.copyList ? point.copyList : [], //抄送人回显的数据
                  reviewUsers:
                    point.rectifyVo && point.rectifyVo.reviewUserName
                      ? [
                          {
                            label: point.rectifyVo.reviewUserName,
                            value: point.rectifyVo.reviewUserId
                          }
                        ]
                      : [], //复查人回显的数据
                  responsibleUsers:
                    point.rectifyVo && point.rectifyVo.responsibleUserName
                      ? [
                          {
                            label: point.rectifyVo.responsibleUserName,
                            value: point.rectifyVo.responsibleUserId
                          }
                        ]
                      : "" //整改责任人回显的数据
                };
                this.measurePointsForms.push(form);
              });
              this.active = this.measurePointsForms[0].id;
            }
          });
          Util.processError(this, response);
        })
        .catch(err => {
          this.loading = false;
          this.$closeLoading();
          console.log(err);
        });
    },
    // 生成整改单
    save() {
      if (this.validateForm()) {
        this.$openLoading();
        /**
         *   endTime:
              (item.rectifyDto.endTime = Util.formatDate(
                new Date(item.rectifyDto.endTime),
                "yyyy-MM-dd"
              )) + " 23:59:59", //截止时间
               isCurrentRect: item.rectifyDto.isCurrentRect, //是否现场整改
         */
        let result = [];
        this.measurePointsForms.forEach(item => {
          if (item.canDel == 0) {
            let obj = this.deepCopy(item);
            obj.measureId = this.measureId;
            obj.rectifyDto = {
              days: item.rectifyDto.days, //整改期限
              rectCopyUserIds: item.rectifyDto.rectCopyUserIds,
              rectificationRequirements:
                item.rectifyDto.rectificationRequirements, //整改要求
              responsibleUnitId: item.rectifyDto.responsibleUnitId, //整改单位
              responsibleUserId: item.rectifyDto.responsibleUserId.join(","), //整改责任人
              reviewUser: item.rectifyDto.reviewUser.join(",") //复查人
            };
            result.push(obj);
          }
        });
        this.$A
          .Go("post", this.api.CreateBillApi, { obj: result })
          .then(response => {
            this.$closeLoading();
            Util.processRes(response, () => {
              this.$router.push({
                name: "TaskModeRealMeasure"
              });
            });
            Util.processError(this, response);
          })
          .catch(err => {
            this.$closeLoading();
            console.log(err);
          });
      }
    },
    deepCopy(obj) {
      var result = Array.isArray(obj) ? [] : {};
      for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
          if (typeof obj[key] === "object" && obj[key] !== null) {
            result[key] = this.deepCopy(obj[key]); //递归复制
          } else {
            result[key] = obj[key];
          }
        }
      }
      return result;
    },
    // 删除
    del(index) {
      this.$nextTick(() => {
        MessageBox({
          message: "确认删除该问题？",
          showCancelButton: true,
          showConfirmButton: true,
          confirmButtonText: "确认",
          cancelButtonText: "取消"
        })
          .then((value, action) => {
            if (value == "confirm") {
              //if (this.measurePointsForms.length < 2) {
              //return;
              //} else {
              this.measurePointsForms.splice(index, 1);
              this.measurePoints.splice(index, 1);
              //}
            } else {
            }
          })
          .catch(err => {});
      });
    }
  },
  destroyed() {}
};
</script>

<style lang="scss">
#CreateBill {
  .lan-nodata {
    height: 100%;
    background: #fff;
  }
  .card-point {
    box-shadow: 0rem 0.02rem 0.08rem 0rem rgba(182, 182, 182, 0.4);
    border-radius: 0.04rem 0.04rem 0rem 0rem;
    margin-bottom: 0.14rem;
    .mu-expansion-panel {
      margin: 0.05rem 0;
      box-shadow: none;
    }
    .mu-expansion-panel-header {
      padding: 0;
    }
    .mu-divider {
      width: 100%;
    }
    .mu-expansion-toggle-btn.mu-button {
      position: absolute;
      right: 10px;
      top: 0.39rem;
    }
    .mu-expansion-panel__expand .mu-expansion-panel-header {
      border-bottom: 1px dashed #e0e0e0;
    }
    .mu-expansion-panel-content {
      padding: 0;
    }
    .imgTrigger {
      height: 0.75rem;
      width: 0.75rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .userTrigger {
      height: 0.75rem;
      width: 0.6rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #0080cb;
      .add {
        border-radius: 0.25rem;
        width: 0.5rem;
        height: 0.5rem;
        border: 0.01rem solid rgba(0, 128, 203, 1);
      }
    }
    .userBox {
      margin-top: 4px;
      position: relative;
      height: 0.75rem;
      width: 0.6rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #0080cb;
      border-radius: 0.02rem;
      overflow: hidden;
      color: rgba(61, 61, 61, 1);
      .add {
        border-radius: 0.25rem;
        width: 0.5rem;
        height: 0.5rem;
        font-size: 0.26rem;
        color: #fff;
        background: rgba(0, 128, 203, 1);
        border: 0.01rem solid rgba(0, 128, 203, 1);
      }
    }
  }
}
</style>
